home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / DBEDIT.ASM < prev    next >
Assembly Source File  |  1992-06-11  |  16KB  |  333 lines

  1. ;dbedit.asm 
  2. ;Debugger editing routines
  3. ;               
  4. .386P
  5. ;---------------------------------------------------------------------------- 
  6. ;Copyright 1991, 1992 ASMicro Co. 
  7. ;7/6/91       Rick Knoblaugh
  8. ;-----------------------------------------------------------------------------
  9.                 include dbequ.inc
  10.                 include dbmac.inc
  11.                 include dbstruc.inc
  12.  
  13. data            segment para public 'data16' use16
  14.                 extrn   get_out:word
  15.                 extrn   edit_routine:word
  16.                 extrn   cmd_buffer:byte
  17.                 extrn   config_attrib:byte
  18.                 extrn   spec_keys:byte
  19.                 extrn   SPEC_KEYS_LEN:abs
  20.                 extrn   key_buf:word      
  21.                 extrn   buf_put:word      
  22.                 extrn   buf_get:word      
  23.  
  24. BUF_START       equ     offset key_buf
  25. BUF_END         equ     offset buf_put
  26. data            ends
  27.  
  28. zcode    segment para public 'code16' use16
  29.                 extrn   set_cursor_pos:near
  30.  
  31.                 public  editor, clear_buffer
  32.                 public  do_left, do_right, do_rub_out, do_insert, do_delete
  33.     assume cs:zcode, ds:data, es:nothing
  34.  
  35.  
  36. ;----------------------------------------------------------------------
  37. ;editor - Accept input from keyboard.                                 |
  38. ;                                                                     |
  39. ;             Enter: es = video segment                               |
  40. ;                    di = offset into video buffer of first           |
  41. ;                         position for user input                     |
  42. ;                    ds = debugger data segment                       |
  43. ;                    si = offset of buffer in which to store data     |
  44. ;                    dl = max chars allowed                           |
  45. ;                    dh = max chars entered so far                    |
  46. ;                    bx = counter of chars being input                |
  47. ;               get_out = value for key that additionally (besides    |
  48. ;                         ESC and CR) causes an exit from edit        |
  49. ;                         (zero if none).                             |
  50. ;                                                                     |
  51. ;          edit_routine = offset of editing routine (zero if none).   |
  52. ;                         This routine should return with carry set   |
  53. ;                         if input is illegal.                        |
  54. ;                                                                     |
  55. ;                                                                     |
  56. ;              Exit: dh = maximum chars entered                       |
  57. ;                    ax = last key entered (will be either ESC, CR, or|
  58. ;                         get_out).                                   |
  59. ;                                                                     |
  60. ;  CX saved.                                                          |
  61. ;----------------------------------------------------------------------
  62. editor          proc    near
  63.                 push    cx
  64. editor_100:
  65.                 mov     ax, di
  66.                 shr     ax, 1 
  67.                 call    set_cursor_pos
  68.                 call    get_char
  69.                 call    check_spec_keys
  70.                 or      cx, cx                  ;key was found?      
  71.                 jnz     short editor_100        ;if not
  72.                 or      al, al                  ;extended key?
  73.                 jz      short editor_100        ;if so, don't want        
  74.  
  75. editor_150:
  76.                 cmp     al, CR                  ;enter key?
  77.                 je      short editor_999
  78.                 jb      short editor_100        ;if below, don't want        
  79.                 cmp     al, ESC_KEY             ;esc
  80.                 je      short editor_999
  81.                 cmp     ax, get_out             ;a "get out" key?
  82.                 je      short editor_999
  83.                 cmp     edit_routine, 0         ;editing specified?
  84.                 je      short editor_170        ;if not, continue
  85.                 call    word ptr edit_routine
  86.                 jc      short editor_100           ;if not allowable input        
  87. editor_170:
  88.                 mov     [si + bx], al           ;store the char
  89.                 WRITE_CHAR                      ;display it
  90.                 inc     bl                      ;increment counter
  91.                 cmp     bl, dh                  ;char counter vs max entered
  92.                 jb      short editor_200   
  93.                 cmp     dh, dl                  ;char counter vs max allowed
  94.                 jb     short editor_180
  95. editor_175:
  96.                 dec     bl
  97.                 jmp     short editor_100   
  98.  
  99. editor_180:                                             
  100.                 inc     dh                      ;advance max entered count
  101.                 cmp     dh, dl                  ;char counter vs max allowed
  102.                 je      short editor_175
  103. editor_200:                                             
  104.                 inc     di
  105.                 inc     di                      ;advance cursor
  106.                 jmp     short editor_100   
  107. editor_999:
  108.                 pop     cx
  109.                 ret
  110. editor          endp
  111.  
  112. clear_buffer    proc    near
  113.                 push    ax
  114.                 push    cx
  115.                 push    di
  116.                 push    es
  117.  
  118.                 push    ds
  119.                 pop     es
  120.  
  121.                 mov     cx, CMD_MAX_LEN
  122.                 mov     di, offset cmd_buffer
  123.                 mov     al, ' '
  124.                 rep     stosb
  125.  
  126.                 pop     es
  127.                 pop     di
  128.                 pop     cx
  129.                 pop     ax
  130.                 ret
  131. clear_buffer    endp
  132.  
  133.  
  134. ;----------------------------------------------------------------------
  135. ;check_spec_keys - Look for editing keys and process edit if found.   |
  136. ;                                                                     |
  137. ;             Enter: si = offset of start of buffer being edited      |
  138. ;                    ax = scan code/char of key stroke                |
  139. ;                    bx = char counter                                |
  140. ;                    dx = max chars entered/max chars allowed         |
  141. ;                 es:di = seg:offset into video buffer                |
  142. ;                                                                     |
  143. ;             Exit:                                                   |
  144. ;                    cx = zero if key not found in table              |
  145. ;                    bx, di may be altered per arrow keys etc.        |
  146. ;                                                                     |
  147. ;           SI saved                                                  |
  148. ;----------------------------------------------------------------------
  149. check_spec_keys proc    near                    
  150.                 push    si                      ;save start of buffer
  151.                 mov     cx, SPEC_KEYS_LEN
  152.                 mov     si, offset spec_keys
  153. check_sp100:
  154.                 cmp     ax, [si].key_data
  155.                 jne     short check_sp200
  156.                 mov     cx, [si].key_routine
  157.                 pop     si                      ;restore start of buffer
  158.                 call    cx                      ;perform special key routine
  159.                 ret                      
  160. check_sp200:
  161.                 add     si, size sp_key_tab                
  162.                 loop    check_sp100
  163. check_sp300:
  164.                 pop     si        
  165. check_sp900:
  166.                 ret
  167. check_spec_keys endp
  168.  
  169.  
  170. ;----------------------------------------------------------------------
  171. ; do_rub_out - process the rub out key.                               |
  172. ;                                                                     |
  173. ;             Enter: si = offset of start of buffer being edited      |
  174. ;                    ax = scan code/char of key stroke                |
  175. ;                    bx = char counter                                |
  176. ;                    dx = max chars entered/max chars allowed         |
  177. ;                 es:di = seg:offset into video buffer                |
  178. ;                                                                     |
  179. ;              Exit: bx dh, and di updated if rub out processed.      |
  180. ;                                                                     |
  181. ;----------------------------------------------------------------------
  182. do_rub_out      proc    near
  183.                 or      bx, bx                  ;already at far left?
  184.                 jz      short do_rub_999        ;if so, nothing to do
  185.                 mov     al,  dh                 ;get max entered
  186.                 sub     al, bl                  ;minus current offset
  187.                 cmp     al, 1                   ;at max allowable position?
  188.                 jne     short do_rub_500
  189.                 call    do_delete               ;if so, get rid of it
  190.                 jmp     short do_rub_999
  191. do_rub_500:
  192.                 cmp     bl, dh                  ;see if at left of max
  193.                 jb      short do_rub_600        ;if so, don't subtract char
  194.                 dec     dh                      ;have 1 less char
  195. do_rub_600:
  196.  
  197.                 dec     bx
  198.                 mov     al, ' '
  199.                 mov     [si+ bx], al            ;space out what was there
  200.                 sub     di, 2                   ;move back in video buffer
  201.                 WRITE_CHAR                
  202.  
  203. do_rub_999:
  204.                 ret
  205. do_rub_out      endp
  206.  
  207. ;----------------------------------------------------------------------
  208. ; do_left - process left arrow key.                                   |
  209. ;                                                                     |
  210. ;             Enter: si = offset of start of buffer being edited      |
  211. ;                    ax = scan code/char of key stroke                |
  212. ;                    bx = char counter                                |
  213. ;                    dx = max chars entered/max chars allowed         |
  214. ;                 es:di = seg:offset into video buffer                |
  215. ;                                                                     |
  216. ;              Exit: bx decremented if left arrow processed.          |
  217. ;                                                                     |
  218. ;----------------------------------------------------------------------
  219. do_left         proc    near
  220.                 or      bx, bx                  ;already at far left?
  221.                 jz      short do_left_999       ;if so, nothing to do
  222.                 dec     bx
  223.                 sub     di, 2
  224. do_left_999:
  225.                 ret
  226. do_left         endp
  227.  
  228. ;----------------------------------------------------------------------
  229. ; do_right - process right arrow key.                                 |
  230. ;                                                                     |
  231. ;             Enter: si = offset of start of buffer being edited      |
  232. ;                    ax = scan code/char of key stroke                |
  233. ;                    bx = char counter                                |
  234. ;                    dx = max chars entered/max chars allowed         |
  235. ;                 es:di = seg:offset into video buffer                |
  236. ;                                                                     |
  237. ;              Exit: bx incrmented if right arrow processed.          |
  238. ;                                                                     |
  239. ;----------------------------------------------------------------------
  240. do_right        proc    near
  241.                 or      dh, dh                  ;any chars entered?
  242.                 jz      short do_right_999
  243.                 mov     al, dl                  ;get max allowed
  244.                 dec     al
  245.                 cmp     bl, al                  ;already there?
  246.                 je      short do_right_999      ;if so, don't go
  247.                 cmp     bl, dh                  ;at max entered?
  248.                 je      short do_right_999
  249.                 inc     bx
  250.                 add     di, 2
  251. do_right_999:
  252.                 ret
  253. do_right        endp
  254.  
  255. do_insert       proc    near
  256. ;
  257. ;Put logic to handle insert key here.
  258. ;
  259.                 ret
  260. do_insert       endp
  261.  
  262. ;----------------------------------------------------------------------
  263. ; do_delete - process delete key.                                     |
  264. ;                                                                     |
  265. ;             Enter: si = offset of start of buffer being edited      |
  266. ;                    ax = scan code/char of key stroke                |
  267. ;                    bx = char counter                                |
  268. ;                    dx = max chars entered/max chars allowed         |
  269. ;                 es:di = seg:offset into video buffer                |
  270. ;                                                                     |
  271. ;              Exit: All chars moved left in buffer. dh decremented.  |
  272. ;                                                                     |
  273. ;----------------------------------------------------------------------
  274. do_delete       proc    near
  275.                 or      dh, dh                  ;any chars entered
  276.                 jz      short do_del_999
  277.                 cmp     bl, dh                  ;past where entered
  278.                 jz      short do_del_999        ;if so, no delete        
  279.                 push    bx
  280.                 push    cx
  281.                 push    di
  282.                 
  283.                 xor     ch, ch
  284.                 mov     cl, dh                  ;get max entered
  285.                 sub     cl, bl                  ;minus offset where located
  286.                 dec     cx
  287.                 jcxz    do_del_800              ;if at last allowable char
  288.                                                 
  289. do_del_100:
  290.                 mov     al, [si + bx][1]        ;get next char
  291.                 WRITE_POS                       ;write char and position cursor
  292.                 mov     [si + bx], al
  293.                 inc     bx
  294.                 loop    do_del_100
  295. do_del_800:
  296.                 mov     al, ' '
  297.                 mov     [si + bx], al           ;space out last char
  298.                 WRITE_CHAR                      ;write char and position cursor
  299.                 dec     dh                      ;have one less char
  300.                 pop     di
  301.                 pop     cx
  302.                 pop     bx
  303. do_del_999:
  304.                 ret
  305. do_delete       endp
  306.  
  307. get_char        proc    near
  308.                 push    bx
  309. get_c100:
  310.                 mov     ax, buf_put
  311.                 cmp     buf_get, ax             ;if no keys available
  312.                 je      short get_c100          ;wait for one
  313.                 mov     bx, buf_get
  314.                 mov     ax, [bx]                ;get char and scan code
  315.                 cmp     al, 0e0h                ;separate cursor pad             
  316.                 jne     short get_c150
  317.                 sub     al, al
  318. get_c150:
  319.                 
  320.                 add     bx, 2
  321.                 cmp     bx, BUF_END             ;at end?      
  322.                 jne     short get_c200
  323.                 mov     bx, BUF_START           ;if so, wrap
  324. get_c200:
  325.                 mov     buf_get, bx             ;next spot to get
  326.                 pop     bx
  327.                 ret
  328. get_char        endp        
  329.  
  330. zcode           ends
  331.             end          
  332.  
  333.